package com.example.kafka.config;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @author lingGao
 */
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(MetricKafkaProperties.class)
public class KafkaConfig {

    private final MetricKafkaProperties metricKafkaProperties;

    public KafkaConfig(MetricKafkaProperties metricKafkaProperties) {
        this.metricKafkaProperties = metricKafkaProperties;
    }

    @Bean
    public KafkaProducer<String, String> producer() {
        Properties props = new Properties();
        props.putAll(metricKafkaProperties.getProperties());
        return new KafkaProducer<>(props);
    }

}
